//
//  LSWeatherModel.m
//  KuaiYi
//
//  Created by 袁应荣 on 2016/11/13.
//  Copyright © 2016年 HeiMa. All rights reserved.
//

#import "LSWeatherModel.h"
#import "NetworkTool.h"
#import <YYModel.h>

@implementation LSWeatherModel

+ (instancetype)shareModel
{
    static id instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        instance = [[self alloc] init];
    });
    return instance;
}

- (void)loadWeatherDataWithURLStr:(NSString *)URLStr parameters:(id)parameters success:(void (^)(NSArray *))successBlock failed:(void (^)(NSError *))failedBlock
{
    [[NetworkTool sharedTool] GETWithURLStr:URLStr parameters:parameters success:^(NSDictionary *responseObject) {
        
        NSArray *resultsArr = responseObject[@"results"];
        NSDictionary *resultDict = resultsArr[0];
        if (resultDict[@"currentCity"] != nil) {
            self.currentCity = resultDict[@"currentCity"];
        }
        
        NSArray *weather_dataArr = resultDict[@"weather_data"];
        NSArray *weatherArr = [NSArray yy_modelArrayWithClass:[LSWeatherModel class] json:weather_dataArr];
        if (successBlock != nil) {
            
            successBlock(weatherArr);
        }
        
    } failed:^(NSError *error) {
        if (failedBlock != nil) {
            
            failedBlock(error);
        }
        
    }];
}



- (NSString *)description
{
    return [NSString stringWithFormat:@"%@-%@-%@-%@\n%@\n%@",self.currentCity,self.date,self.weather,self.temperature,self.dayPictureUrl,self.nightPictureUrl];
}

@end
